
package View;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class LoginView extends JFrame{
    private JLabel userNameL = new JLabel("User Name :");
    private JTextField userNameTF = new JTextField(10);
    private JLabel passwordL = new JLabel("Password :");
    private JTextField passwordTF = new JTextField(10);
    private JButton loginB = new JButton("Login");
    private JButton cancelB = new JButton("Cancel");
    
    //constructor
    public LoginView(){
        JPanel loginPanel = new JPanel();
        
        loginPanel.add(userNameL);
        loginPanel.add(userNameTF);
        loginPanel.add(passwordL);
        loginPanel.add(passwordTF);
        loginPanel.add(loginB);
        loginPanel.add(cancelB);
        
        loginPanel.setLayout(new GridLayout(3, 2));
        this.add(loginPanel);
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        this.setSize(400, 120);
        this.setLocationRelativeTo(null);//set frame location to center on screen
        //this.setVisible(true);       
    }

    public void setUserNameTF(String userNameTF) {
        this.userNameTF.setText(userNameTF);
    }

    public void setPasswordTF(String passwordTF) {
        this.passwordTF.setText(passwordTF);
    }
    
    public String getUserName(){
        return userNameTF.getText();
    }
    
    public String getPassword(){
        return passwordTF.getText();
    }
    
    //If the  LoginView Button is clicked execute a method
    //in the LoginController named actionPerformed
    public void addLoginButtonListener(ActionListener listenForLoginButton){
        loginB.addActionListener(listenForLoginButton);
    }

    //If the Cancel Button is clicked execute a method
    //in the LoginController named actionPerformed
    public void addCancelButtonListener(ActionListener listenForCancelButton){
        cancelB.addActionListener(listenForCancelButton);
    }

  
}
